<template>
	<!-- pages/my_collection/my_collection.wxml -->
	<view class="container">
		<view class="page-foot bg-white">
			<view class="ptb10 m-hairline--top" @click="addBuilding()">
				<view class="g-btn3 mlrauto">新增楼盘</view>
			</view>
		</view>

		<view class="searchbox">
		<!-- 	<view class="search_box flex-box flex-center">
				<image src="/static/icon/search.png" mode="aspectFill" class="search"></image>
				<input type="text" placeholder="请输入你要搜索的内容" v-model="q" confirm-type="search" @confirm="search" class="fs24" placeholder-class="cola">
			</view> -->
			<view class="nav_box flex-box">
				<view class="" :class="{'active': searchType==0}" @click="tabClick(0)">全部</view>
				<view class="" :class="{'active': searchType==1}" @click="tabClick(1)">审核中</view>
				<view class="" :class="{'active': searchType==2}" @click="tabClick(2)">已过审</view>
				<view class="" :class="{'active': searchType==3}" @click="tabClick(3)">未过审</view>
			</view>
		</view>

		<view class="houselist">
			<template v-if="nowList.total > 0">
				<template v-for="(item, index) in nowList.data" >
					<div style="padding-bottom: 30rpx;">
					<navigator :url="'/pages/house/building_detail/building_detail?id=' + item.house_id"
						class="houseitem flex">

						<image :src="item.house.image_text" class="houseimg" mode="aspectFill"></image>
						<view class="flex-grow-1">
							<view class="housename single-line">{{ item.house.name }}</view>
							<view class="area-size flex-box flex-between">
								<text>{{ item.house.region }}									</text>
								<text>{{ item.house.min_space }}㎡-{{ item.house.max_space }}㎡</text>
							</view>
							<view class="targetbox flex flex-wrap">
								<view class="targetitem" v-for="(targets, index1) in item.house.house_tag_ids_text_arr">
									{{ targets }}</view>
							</view>
							<view class="housecost">
								¥
								<text>{{ item.house.price }}</text>
								/㎡
							</view>
							<view v-if="searchType===0" class="area-size flex-box flex-between">{{ item.status_name }}</view>
						</view>
					</navigator>
					<view class="flex-box source_list" >
						<view class="status1 flex-grow-1" :class="{status2: item.status=='hidden'}">已{{item.status_t}}</view>
            <view class="btn3" @click="check(item.house.id)" >查看</view>
            <template v-if="item.status_name==='已过审'">
              <view class="btn1" @click="multiClick(item.house.id,index,'下架','hidden')" v-if="item.status == 'normal'">下架</view>
              <view class="btn2" @click="multiClick(item.house.id,index,'上架','normal')" v-else>上架</view>
            </template>

					</view>
					</div>
				</template>
				<u-loadmore :status="loadStatus" fontSize="24" line loading-text="努力加载中" loadmore-text="轻轻上拉"
					nomore-text="没有更多了" />
			</template>
			<template v-else>
				<u-empty mode="data" text="暂无数据" textSize="24" icon="/static/images/none-data.png">
				</u-empty>
			</template>
		</view>
	</view>
</template>

<script>
	// pages/my_collection/my_collection.js
	const app = getApp();

	const functions = require('../../../utils/functions.js');

	export default {
		data() {
			return {
				// 列表
				nowList: {
					total: 0,
					current_page: 0,
					last_page: 1,
					data: []
				},
				searchType:0,
				loadStatus: 'loadmore', //加载状态
				targets: []
			};
		}
		/**
		 * 生命周期函数--监听页面加载
		 */
		,
		onLoad: function(options) {
			this.initData();
		},
		onShow() {
				this.initData();
		},

		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {
			uni.showNavigationBarLoading(); //在标题栏中显示加载

			var that = this; //模拟加载

			setTimeout(function() {
				that.initData();
				uni.stopPullDownRefresh(); //停止下拉刷新
			}, 1500);
		},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		// onShareAppMessage: function () {
		// }
		onReachBottom: function() {
			if (this.nowList.current_page >= this.nowList.last_page) {
				this.loadStatus = 'nomore';
				return false;
			} else {
				this.getnowList();
			}
		},
		/**
		 * 用户点击右上角分享
		 */
		methods: {
			// 获取列表信息
			getnowList: function() {
				var that = this;
				var json = {};
				json.page = Number(that.nowList.current_page) + 1;
				json.searchType = that.searchType
				if (json.page > 1 && that.nowList.current_page >= that.nowList.last_page) {
					functions.toast('已加载到底部了');
					this.loadStatus = 'nomore';
					return false;
				}
				this.loadStatus = 'loading';
				functions.getAjaxList(that, '/api/xiluhouse/appoint/my_house_list', json, function(res) {
					var nowList = res.data;

					if (json.page > 1) {
						var now_nowList_data = that.nowList.data || [];
						var now_nowList_data = now_nowList_data.concat(nowList.data);
						nowList.data = now_nowList_data;
					}

					that.nowList = nowList

				});
			},
			addBuilding(){
				uni.navigateTo({
					url: '/pages/member/new_house2/new_house2'
				})
			},
			tabClick(type){

				var that = this;

				that.nowList.current_page = 0
				that.searchType = type
				that.getnowList();
			},
      check(id){
        uni.navigateTo({
          url: '/pages/member/new_house2/new_house2?id='+id
        })
      },
			multiClick(id,index,msg,status){
				let that = this;
				let houseList = this.nowList.data;
				uni.showModal({
					title:'提示',
					content: '确认操作',
					success(res) {
						console.log(res)
						if(res.confirm){

							functions.getAjaxList(that, '/api/xiluhouse.broker/multi_house_status', {id,status}, function(ret) {
								uni.showToast({
								 	title:ret.msg
								 });
								houseList[index].status = status;
								houseList[index].status_t = msg;
								console.log(houseList)
								that.nowList.data = houseList;

							});


						}
					}
				})
			},
			// 获取所有可下拉刷新更新的数据
			initData: function() {
				var that = this;

				that.nowList.current_page = 0

				that.getnowList();
			}
		}
	};
</script>
<style lang="scss">
	.houselist {
		padding: 110rpx 40rpx;
	}

	.houselist .houseitem {

	}

	.houselist .houseitem .houseimg {
		width: 240rpx;
		height: 190rpx;
		border-radius: 10rpx;
		margin-right: 20rpx;
	}

	.houselist .housename {
		font-size: 30rpx;
		padding-bottom: 10rpx;
	}

	.houselist .area-size {
		font-size: 24rpx;
		color: #898989;
	}

	.houselist .targetbox {
		padding: 14rpx 0 0;
	}

	.houselist .targetitem {
		padding: 2rpx 4rpx;
		background: #cce9ff;
		font-size: 18rpx;
		color: var(--blue);
		border-radius: 2rpx;
		margin-right: 10rpx;
		margin-bottom: 12rpx;
	}

	.houselist .housecost {
		color: #f8532f;
		font-size: 24rpx;
	}

	.houselist .housecost text {
		font-size: 34rpx;
	}

	.houselist .event {
		padding-top: 11rpx;
		font-size: 18px;
		color: #898989;
	}

	.houselist .event .bao {
		width: 26rpx;
		text-align: center;
		line-height: 26rpx;
		font-size: 18rpx;
		height: 26rpx;
		border-radius: 5rpx;
		background: linear-gradient(180deg, #00c4ff, var(--blue));
		color: #fff;
		margin-right: 10rpx;
	}

	.houselist .event .dong {
		width: 26rpx;
		text-align: center;
		line-height: 26rpx;
		font-size: 18rpx;
		height: 26rpx;
		border-radius: 5rpx;
		background: linear-gradient(270deg, #ff6635, #ffb45c);
		color: #fff;
		margin-right: 10rpx;
	}

	.houselist .icon_collect {
		width: 30rpx;
		height: 30rpx;
		margin-right: 10rpx;
	}
	.searchbox {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		background-color: #fff;
		z-index: 10;

		.search_box {
			padding: 0 30rpx;
			height: 72rpx;
			background: #F7F9FC;
			border-radius: 36rpx;
			margin: 14rpx 30rpx;

			.search {
				width: 24rpx;
				height: 24rpx;
				margin-right: 12rpx;
			}
		}

		.nav_box {
			padding: 0 30rpx;
			font-size: 30rpx;
			color: #898989;
			text-align: center;
			line-height: 100rpx;

			view {
				position: relative;
				margin-right: 50rpx;

				text {
					position: absolute;
					right: 2rpx;
					top: 18rpx;
					display: block;
					width: 24rpx;
					height: 24rpx;
					background: #FF3B45;
					border-radius: 50%;
					font-size: 18rpx;
					color: #FFFFFF;
					line-height: 24rpx;
					text-align: center;
				}
			}

			view.active {
				font-size: 36rpx;
				color: #101010;
				font-weight: bold;
				position: relative;
			}

			view.active::after {
				content: "";
				display: block;
				width: 20rpx;
				height: 4rpx;
				background: var(--normal);
				border-radius: 3rpx;
				position: absolute;
				bottom: 10rpx;
				left: 50%;
				transform: translateX(-50%);
			}

		}
	}
	.source_list {
		position: relative;
		z-index: 1;





		.status1 {
			color: #333333;
		}

		.status2 {
			color: #898989;
		}

		.btn1 {
			width: 150rpx;
			height: 60rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 30rpx;
			border: 1px solid #CCCCCC;
			color: #898989;
			font-size: 24rpx;
			background-color: #fff;
			margin-left: 20rpx;
		}

		.btn2 {
			width: 150rpx;
			height: 60rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 30rpx;
			border: 1px solid var(--normal);
			background-color: var(--normal);
			color: #fff;
			font-size: 24rpx;
			margin-left: 20rpx;
		}

		.btn3 {
			width: 150rpx;
			height: 60rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 30rpx;
			border: 1px solid var(--normal);
			color: var(--normal);
			font-size: 24rpx;
			margin-left: 20rpx;
		}

		.avatar {
			width: 40rpx;
			height: 40rpx;
			border-radius: 50%;
			margin-right: 15rpx;
		}

		.tel {
			padding: 0;
			margin: 0;
			line-height: 1;

			image {
				width: 30rpx;
				height: 30rpx;
				margin-left: 15rpx;
			}
		}


	}
</style>
